package com.sllp.C71S3TsllpShop.web.back;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sllp.C71S3TsllpShop.bean.Admin;
import com.sllp.C71S3TsllpShop.bean.Business;
import com.sllp.C71S3TsllpShop.bean.Result;
import com.sllp.C71S3TsllpShop.biz.impl.BusinessBizImpl;

@Controller
public class BackBusinessAuditAction {

	@Resource
	private BusinessBizImpl bbiz;
	
	@GetMapping("back/toBusinessAudit.do")
	public String toBusinessAudit(Model m) {
		List<Business> blist=bbiz.findBusinessByCondition(null, 1,3);
		System.out.println(blist);
		m.addAttribute("businesslist", blist);
		return "back/business-audit::businessAudit";
	}
	
	@PostMapping("back/businessFind.do")
	public String businessFind(Business business,Model m) {
		if(business.getState() != null && business.getState() == 0) {
			business.setState(null);
		}
		m.addAttribute("businesslist",bbiz.findBusinessByCondition(business,1,3));
		return "back/business-audit::businessShowTable";
	}
	
	@ResponseBody
	@PostMapping("back/toShowBusinessDetils.do")
	public Business toShowBusinessDetils(Business business) {
		Business b=bbiz.findBusinessByCondition(business,null,null).get(0);
		return b;
	}
	
	@ResponseBody
	@PostMapping("back/changeBusinessState.do")
	public Result changeBusinessState(Business business,Model m) {
		return bbiz.updateBusinessState(business);
	}
	
	@PostMapping("back/businessShowToPage.do")
	public String businessShowToPage(Business business,int page,Model m) {
		if(business.getState() != null && business.getState() == 0) {
			business.setState(null);
		}
		m.addAttribute("businesslist", bbiz.findBusinessByCondition(business, page, 3));
		return "back/business-audit::businessShowTable";
	}
	
}
